$(function () {
    findById();
});

function findById() {
    let data = myAjax("/back/user/findById",
        {id: sessionStorage.getItem("userID")},
        "get");
    setData(data.data);
}

function setData(data) {
    layui.use(['form'],
        function () {
            $ = layui.jquery;
            var form = layui.form;


            $("#username").val(data.username);
            $("#email").val(data.email);
            $('input[name="sex"][title=' + data.sex + ']').prop('checked', 'checked');
            $('input:checkbox[name=hobby]').each(function (index, dom) {
                let hobby = data.hobby;
                let hobbys = hobby.split(",");
                for (let i = 0; i < hobbys.length; i++) {
                    if (hobbys[i] == dom.title)
                        $(this).attr('checked', true);
                }

            });
            $("#enable").val(data.enable);
            $("#birthday").val(data.birthday);


            form.render();//刷新表单
        });

}